package com.totoro.service.impl;

import com.totoro.mapper.IndexMapper;
import com.totoro.pojo.IndexCategory;
import com.totoro.pojo.Product;
import com.totoro.pojo.Shop;
import com.totoro.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author TOTORO
 * @date 2021/8/30 23:20
 */
@Service
public class IndexServiceImpl implements IndexService {
    @Autowired
    private IndexMapper indexMapper;

    @Override
    public List<IndexCategory> findAllOneCategory() {
        return indexMapper.findAllOneCategory();
    }

    @Override
    public List<IndexCategory> findAllTwoCategoryByOneCategoryId(int icId) {
        return indexMapper.findAllTwoCategoryByOneCategoryId(icId);
    }

    @Override
    public List<IndexCategory> findAllThreeCategoryByTwoCategoryId(int icId) {
        return indexMapper.findAllThreeCategoryByTwoCategoryId(icId);
    }

    @Override
    public Integer updateCategoryDetail(IndexCategory indexCategory) {
        return indexMapper.updateCategoryDetail(indexCategory);
    }

    @Override
    public List<Shop> findMaxScoreThreeAShop() {
        return indexMapper.findMaxScoreThreeAShop();
    }

    @Override
    public Map<Shop, List<Product>> findMaxDealProductByShop() {
        List<Shop> shops = indexMapper.findMaxScoreThreeAShop();
        Map<Shop, List<Product>> shopListMap = new LinkedHashMap<>();
        for (Shop shop : shops) {
           List<Product> list = indexMapper.findMaxDealProductByShop(shop.getId());
           shopListMap.put(shop, list);
        }
        return shopListMap;
    }
}
